﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Webdiyer.WebControls.Mvc;
using System.Data;
using ElingOA6_Admin_DSJCJ.Common;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{
    /// <summary>
    /// 前台显示页面
    /// </summary>
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class FrontShowController : Controller
    {
        /// <summary>
        /// 重点督查（文件阅办）前台显示页面
        /// </summary>
        /// <param name="lb">类别</param>
        /// <param name="qk">状态</param>
        /// <param name="id">页码</param>
        /// <returns>显示视图</returns>
        public ActionResult TaskShow(string lb, string lb2, string qk, string type = "F", string showlb = "1", int id = 1)
        {
            int pageSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            BLL.CdTaskClass CdTaskClassBLL = new BLL.CdTaskClass();
            ViewData["showLB"] = showlb;
            //int pageSize = 1;
            int pageIndex = id;
            string strWhere = "";
            string Lbs = "";
            if (lb != null && lb != "")
            {
                ViewData["lb"] = lb;
                string[] lbList = lb.Split(',');
                if (lbList.Count() > 1)
                {
                    foreach (string str in lbList)
                    {
                        if (str != "")
                        {
                            if (Lbs == "")
                            {
                                Lbs += "'" + str + "'";
                            }
                            else
                            {
                                Lbs += ",'" + str + "'";
                            }
                        }
                    }
                    strWhere += " FTaskClassCd in(" + Lbs + ")";
                }
                else
                {
                    strWhere += " FTaskClassCd = '" + lb + "'";
                }

                ViewData["CdTaskClassList"] = CdTaskClassBLL.GetModelList(strWhere);
            }
            else
            {
                ViewData["CdTaskClassList"] = CdTaskClassBLL.GetModelList("");
            }

            if (lb2 != null && lb2 != "")
            {
                strWhere = " FTaskClassCd = '" + lb2 + "'";
            }

            if (qk != null && qk != "")
            {
                if (strWhere != "")
                {
                    strWhere += " and FStatus = '" + qk + "'";
                }
                else
                {
                    strWhere += " FStatus = '" + qk + "'";
                }
            }
            else
            {
                if (strWhere != "")
                {
                    strWhere += " and FStatus = '" + 1 + "'";
                }
                else
                {
                    strWhere += " FStatus = '" + 1 + "'";
                }
            }

            if (type != "Q")
            {
                if (strWhere != "")
                {
                    strWhere += " and FStatus = '" + 1 + "'";
                }
                else
                {
                    strWhere += " FStatus = '" + 1 + "'";
                }
            }

            if (showlb == "1")
            {
                ViewData["title"] = "重点督查";
            }
            else
            {
                ViewData["title"] = "文件阅办";
            }
            ViewData["pageIndex"] = id;
            ViewData["qk"] = qk;


            BLL.Common commonBll = new BLL.Common();
            BLL.Task TaskBLL = new BLL.Task();
            string fiedls = "*";
            int total;
            DataSet ds = commonBll.GetListByPage("dbo.fn_getTask('" + Common.GlobalConstant.PARAM_DEPTNO + "')", fiedls, pageSize, pageIndex, strWhere, "FEndDate", 0, out total);
            List<ElingOA6_Admin_DSJCJ.Model.Task> taskList = TaskBLL.DataTableToList(ds.Tables[0]);
            PagedList<Model.Task> pagedDocumentList = new PagedList<Model.Task>(taskList, pageIndex, pageSize, total);
            return View("TaskShow", pagedDocumentList);
        }

        /// <summary>
        /// 人员去向前台显示页面
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="date">时间</param>
        /// <param name="cdLeaveReason">去向类别</param>
        /// <param name="id">页码</param>
        /// <returns>人员去向显示视图</returns>
        public ActionResult LeaveShow(string name, string date, string cdLeaveReason, string type = "F", int id = 1)
        {
            int pageSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            //int pageSize = 1;
            int pageIndex = id;
            string strWhere = "";
            if (name != null && name != "")
            {
                strWhere += " FEmpName like '%" + name + "%'";
            }
            if (date != null && date != "")
            {
                if (strWhere != "")
                {
                    strWhere += " and (datediff(minute,FBeginDate,'" + date + "') <=0 or (datediff(minute,FBeginDate,'" + date + "') >0 and datediff(minute,isnull(FSignOutDate,FEndDate),'" + date + "') <=0))";
                }
                else
                {
                    strWhere += " (datediff(minute,FBeginDate,'" + date + "') <=0 or (datediff(minute,FBeginDate,'" + date + "') >0 and datediff(minute,isnull(FSignOutDate,FEndDate),'" + date + "') <=0))";
                }
            }


            if (cdLeaveReason != null && cdLeaveReason != "")
            {
                if (strWhere != "")
                {
                    strWhere += " and FLeaveReasonCd = '" + cdLeaveReason + "'";
                }
                else
                {
                    strWhere += " FLeaveReasonCd = '" + cdLeaveReason + "'";
                }
            }

            if (type != "Q")
            {
                strWhere += " (datediff(minute,FBeginDate,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "') <=0 or (datediff(minute,FBeginDate,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "') >0 and datediff(minute,isnull(FSignOutDate,FEndDate),'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "') <=0))";
            }

            ViewData["pageIndex"] = id;
            BLL.Common commonBll = new BLL.Common();
            BLL.Leave LeaveBLL = new BLL.Leave();
            BLL.CdLeaveReason CdLeaveReasonBLL = new BLL.CdLeaveReason();
            ViewData["CdLeaveReasonList"] = CdLeaveReasonBLL.GetModelList("");

            ViewData["date"] = date;
            ViewData["name"] = name;
            ViewData["cdLeaveReason"] = cdLeaveReason;
            string fiedls = "*";
            int total;
            DataSet ds = commonBll.GetListByPage("v_Leave", fiedls, pageSize, pageIndex, strWhere, "FEndDate", 0, out total);
            List<ElingOA6_Admin_DSJCJ.Model.Leave> taskList = LeaveBLL.DataTableToList(ds.Tables[0]);
            PagedList<Model.Leave> pagedDocumentList = new PagedList<Model.Leave>(taskList, pageIndex, pageSize, total);
            return View(pagedDocumentList);
        }

        public ActionResult LeaveLook(string id)
        {
            BLL.Leave leaveBLL = new BLL.Leave();
            Model.Leave leaveModel = leaveBLL.GetModel(decimal.Parse(id));
            return View(leaveModel);
        }

        /// <summary>
        /// 重点督查（文件阅办） 单条查看页面
        /// </summary>
        /// <param name="taskID">编号</param>
        /// <returns>查看页面</returns>
        public ActionResult TaskLook(string taskID)
        {
            BLL.Task taskBLL = new BLL.Task();
            Model.Task taskModel = new Model.Task();
            if (taskID != null)
            {
                taskModel = taskBLL.GetModel(decimal.Parse(taskID));
            }
            BLL.TaskDo taskDoBLL = new BLL.TaskDo();
            List<Model.TaskDo> taskDoList = taskDoBLL.GetModelList("FTaskID=" + taskID + "");
            ViewData["ID"] = taskID;
            ViewData["IsShow"] = false;
            if (string.IsNullOrEmpty(OperateSession.get(GlobalConstant.PARAM_LOGINID)))
            {
                ViewData["IsShow"] = false;
            }
            else
            {
                if (taskModel.FDeptNo == OperateSession.get(Common.GlobalConstant.PARAM_DEPTNO))
                {
                    ViewData["IsShow"] = true;
                }
            }
            ViewData["TaskDoList"] = taskDoList;
            ViewData["title"] = taskModel.FTaskClassName;
            BLL.TaskAttach TaskAttachBLL = new BLL.TaskAttach();
            ViewData["TaskAttachList"] = TaskAttachBLL.GetModelList(" FTaskDoID in (select FTaskDoID from dbo.t_TaskDo where FTaskID=" + taskID + " ) ");
            return View(taskModel);
        }


        /// <summary>
        /// 绩效专栏前台显示页面
        /// </summary>
        /// <param name="year">年份</param>
        /// <param name="id">页码</param>
        /// <returns>显示视图</returns>
        public ActionResult PerformancePrjShow(string year, int id = 1)
        {
            BLL.Common commonBll = new BLL.Common();
            BLL.PerformancePrj PerformancePrjBLL = new BLL.PerformancePrj();

            int pageSize = Common.GlobalConstant.CONSTRING_PAGESIZE;
            //int pageSize = 1;
            int pageIndex = id;

            DataSet ds2 = PerformancePrjBLL.GetYear();
            List<string> yearList = new List<string>();
            if (ds2.Tables.Count > 0)
            {
                for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                {
                    yearList.Add(ds2.Tables[0].Rows[i][0].ToString());
                }
            }
            if (yearList.Count > 0)
            {
                if (string.IsNullOrEmpty(year))
                {
                    year = yearList[yearList.Count - 1].ToString();
                }
            }
            else
            {
                year = DateTime.Now.Year.ToString();
            }
            ViewData["YearList"] = yearList;



            string strWhere = "";
            //if (year != null && year != "")
            //{
            //    strWhere += " FYear = '" + year + "'";
            //}
            //else
            //{
            //    if (year == null)
            //    {
            //        year = (DateTime.Now.Year - 1).ToString();
            //    }


            //}
            strWhere += " FYear = '" + year + "'";
            ViewData["pageIndex"] = id;

            string fiedls = "*";
            int total;
            DataSet ds = commonBll.GetListByPage("v_PerformancePrj", fiedls, pageSize, pageIndex, strWhere, "FSeq", 0, out total);
            List<ElingOA6_Admin_DSJCJ.Model.PerformancePrj> taskList = PerformancePrjBLL.DataTableToList(ds.Tables[0]);
            PagedList<Model.PerformancePrj> pagedDocumentList = new PagedList<Model.PerformancePrj>(taskList, pageIndex, pageSize, total);

            ViewData["selValue"] = year;
            return View("PerformancePrjShow", pagedDocumentList);
        }
        /// <summary>
        /// 绩效专栏查看页面
        /// </summary>
        /// <param name="no">编号</param>
        /// <returns>查看视图</returns>
        public ActionResult PerformancePrjLook(string no)
        {
            BLL.PerformancePrj PerformancePrjBLL = new BLL.PerformancePrj();
            Model.PerformancePrj model = PerformancePrjBLL.GetModel(decimal.Parse(no));
            BLL.PerformancePrjEntry PerformancePrjEntryBLL = new BLL.PerformancePrjEntry();
            ViewData["PerformancePrjEntryList"] = PerformancePrjEntryBLL.GetModelList("FPerformancePrjID=" + no);
            return View(model);
        }

    }
}
